var t = require("../../utils/util.js"), e = getApp();

Page({
    data: {
        selectPerson: !0,
        firstPerson: "全部产品分类",
        selectArea: !1,
        imagewidth: 0,
        imageheight: 0,
        baseUrl: e.globalData.baseUrl,
        banners: [],
        store: {},
        server: [],
        yuyueTime: e.globalData.yuyueTime
    },
    imageLoad: function(e) {
        var a = t.imageUtil(e);
        this.setData({
            imagewidth: a.imageWidth,
            imageheight: a.imageHeight
        });
    },
    clickPerson: function() {
        1 == this.data.selectPerson ? this.setData({
            selectArea: !0,
            selectPerson: !1
        }) : this.setData({
            selectArea: !1,
            selectPerson: !0
        });
    },
    mySelect: function(t) {
        this.setData({
            firstPerson: t.target.dataset.me,
            selectPerson: !0,
            selectArea: !1
        });
    },
    onLoad: function(t) {},
    onReady: function() {
        var t = wx.getStorageSync("nickName"), a = wx.getStorageSync("avatarUrl"), n = wx.getStorageSync("userId"), o = wx.getStorageSync("phone");
        t && t.length > 0 && (e.globalData.nickName = t), a && a.length > 0 && (e.globalData.avatarUrl = a), 
        o && o.length > 0 && (e.globalData.phone = o), n && n.length > 0 && (e.globalData.userId = n), 
        n || e.goLogin();
    },
    getLocationL: function() {
        var t = this;
        wx.getLocation({
            type: "wgs84",
            success: function(a) {
                var n = a.latitude, o = a.longitude;
                e.globalData.lat = n, e.globalData.lng = o;
                var i = t, s = e.globalData.urlBase + e.globalData.urlIndex;
                wx.request({
                    url: s,
                    data: {
                        lng: o,
                        lat: n,
                        userId: e.globalData.userId,
                        storeId: e.globalData.storeId
                    },
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function(t) {
                        var a = JSON.parse(t.data);
                        console.log(a), 0 != a.code ? wx.showToast({
                            title: a.msg,
                            icon: "none",
                            duration: 2e3
                        }) : (wx.setNavigationBarTitle({
                            title: a.store.name
                        }), i.setData({
                            store: a.store,
                            server: a.server,
                            banners: a.store.imgs.split(","),
                            serverleng: a.server.length,
                            newsList: a.newsList
                        }), e.globalData.storeId = a.store.id);
                    }
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "获取经纬度失败,请打开定位",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    onShow: function() {
        var t = this;
        if (0 == e.globalData.lat.length || 0 == e.globalData.lng.length) wx.getSetting({
            success: function(e) {
                e.authSetting["scope.userLocation"] && 1 != e.authSetting["scope.userLocation"] ? wx.showModal({
                    title: "您尚未授权获取位置信息",
                    content: "需要获取您的地理位置，请进入个人中心--设置页面确认授权，否则定位功能将无法使用",
                    success: function(t) {
                        wx.navigateTo({
                            url: "../../pages/message/index"
                        });
                    }
                }) : t.getLocationL();
            }
        }); else {
            var a = e.globalData.urlBase + e.globalData.urlIndex;
            this.getinitData(a, {
                lng: e.globalData.lng,
                lat: e.globalData.lat,
                userId: e.globalData.userId,
                storeId: e.globalData.storeId
            });
        }
        this.setData({
            yuyueTime: e.globalData.yuyueTime
        });
    },
    onHide: function() {},
    onUnload: function() {},
    getinitData: function(t, a) {
        var n = this;
        wx.request({
            url: t,
            data: a,
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var a = JSON.parse(t.data);
                0 != a.code ? wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 2e3
                }) : (wx.setNavigationBarTitle({
                    title: a.store.name
                }), n.setData({
                    store: a.store,
                    server: a.server,
                    banners: a.store.imgs.split(","),
                    serverleng: a.server.length,
                    newsList: a.newsList
                }), e.globalData.storeId = a.store.id);
            }
        });
    },
    openMap: function() {
        var t = this;
        wx.openLocation({
            latitude: parseFloat(t.data.store.lat),
            longitude: parseFloat(t.data.store.lng),
            name: t.data.store.name,
            address: t.data.store.address
        });
    },
    onShareAppMessage: function(t) {
        return t.from, {
            title: "首页",
            path: "/pages/index/index",
            success: function(t) {
                console.log("转发成功:" + JSON.stringify(t));
            },
            fail: function(t) {
                console.log("转发失败:" + JSON.stringify(t));
            }
        };
    },
    urlyy: function() {
        wx.navigateTo({
            url: "../product/index"
        });
    },
    urlactivity: function() {
        wx.navigateTo({
            url: "../activity/activity"
        });
    },
    urlhuiyuan: function() {
        wx.navigateTo({
            url: "../huiyuan/huiyuan"
        });
    },
    orderTime: function(t) {
        var e = t.currentTarget.dataset.begintime, a = t.currentTarget.dataset.endtime;
        wx.navigateTo({
            url: "../cTime/cTime?begintime=" + e + "&endtime=" + a
        });
    },
    activityList: function(t) {
        var a = t.currentTarget.dataset.type;
        e.globalData.activityType = a, wx.switchTab({
            url: "../activity/activity"
        });
    },
    navPay: function(t) {
        wx.navigateTo({
            url: "../modulePurchase/pagePay?storeid=" + t.currentTarget.dataset.storeid
        });
    }
});